package com.sdcqjy.property.mode;

import android.content.Context;

import com.google.gson.Gson;
import com.sdcqjy.mylibrary.PrivateFileUtils;
import com.sdcqjy.property.AppLL;

/**
 * Created by 磁磁帅 on 2018/4/14.
 * 功能：
 */

public class LoginMode {
    /**
     * id : 23
     * userName : 谢磁磁
     * passWord : null
     * telePhone : null
     * weChat : null
     * weChatName :
     * actionTime : null
     * createTime : null
     * userType : 3
     * deviceID : oO6881cAd60p9QM2VxMfMt49vi2I
     * isLogin : 1
     * headImageUrl : null
     * openid : oO6881cAd60p9QM2VxMfMt49vi2I
     * token : e9249535-d4a6-4f00-9c36-989526d229a9
     */
    public long id;
    public String userName;
    //public Object passWord;
    public String telePhone;
    //public Object weChat;
    //public String weChatName;
    //public Object actionTime;
    //public Object createTime;
    //public int userType;
    public String deviceID;
    //public int isLogin;
    public String headImageUrl;
    //public String openid;
    public String token;
    public String email;


    //-------------保存数据-------------
    private static LoginMode mode;
    private static final String jsonName = "LoginMode.json";

    public static LoginMode getMode(Context context) {
        if (mode == null) {
            try {
                String txt = new PrivateFileUtils(context, jsonName).getString();
                mode = new Gson().fromJson(txt, LoginMode.class);
            } catch (Exception e) {
            }
            if (mode == null) {
                mode = new LoginMode();
                mode.id = 0;
                AppLL.getAppLL().setLogin(false);
            }
        }
        return mode;
    }

    public static void setMode(Context context, LoginMode mode) {
        if (mode == null) return;
        LoginMode.mode = mode;
        try {
            String s = new Gson().toJson(mode);
            new PrivateFileUtils(context, jsonName).setString(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void clear(Context context) {
        mode = null;
        new PrivateFileUtils(context, jsonName).delete();
    }
}
